﻿using System;
using System.Drawing;

namespace ChessSharp.PiecesCode
{
    /// <summary>
    /// Base Class to define a piece
    /// </summary>
    public abstract class BasePiece
    {
        /// <summary>
        /// Current Board location; 0,0 is bottom left corner
        /// </summary>
        public Point BoardLocation
        {
            get;
            protected set;
        }

        public Color Owner
        {
            get;
            protected set;
        }

        public BasePiece(Point Loc, Color Owner)
        {
            this.BoardLocation = Loc;
            if (Owner != Color.Black && Owner != Color.White)
                throw new Exception("Color must be black or white");

            this.Owner = Owner;
        }

        /// <summary>
        /// Checks if the proposed move location is valid
        /// </summary>
        /// <param name="NewPos">New Board Position</param>
        /// <returns>validity</returns>
        public abstract bool isValidMove(Point NewPos);

        /// <summary>
        /// Returns a list of all valid moves from current position
        /// </summary>
        /// <returns>Valid Points</returns>
        public abstract Point[] ValidMoves();

        public void Move(Point NewPos)
        {
            this.BoardLocation = NewPos;
        }

        public override bool Equals(object obj)
        {
            if (obj.GetType() != this.GetType())
                return false;

            BasePiece P = (BasePiece)obj;

            if (P.Owner != this.Owner)
                return false;

            if (P.BoardLocation != this.BoardLocation)
                return false;

            return true;
        }
    }
}
